{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Goat Latin"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: toGoatLatin"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #山羊拉丁文"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个由若干单词组成的句子&nbsp;<code>sentence</code> ，单词间由空格分隔。每个单词仅由大写和小写英文字母组成。</p>\n",
    "\n",
    "<p>请你将句子转换为 <em>“</em>山羊拉丁文（<em>Goat Latin</em>）<em>”</em>（一种类似于 猪拉丁文&nbsp;- Pig Latin 的虚构语言）。山羊拉丁文的规则如下：</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>如果单词以元音开头（<code>'a'</code>, <code>'e'</code>, <code>'i'</code>, <code>'o'</code>, <code>'u'</code>），在单词后添加<code>\"ma\"</code>。\n",
    "\n",
    "\t<ul>\n",
    "\t\t<li>例如，单词 <code>\"apple\"</code> 变为 <code>\"applema\"</code> 。</li>\n",
    "\t</ul>\n",
    "\t</li>\n",
    "\t<li>如果单词以辅音字母开头（即，非元音字母），移除第一个字符并将它放到末尾，之后再添加<code>\"ma\"</code>。\n",
    "\t<ul>\n",
    "\t\t<li>例如，单词 <code>\"goat\"</code> 变为 <code>\"oatgma\"</code> 。</li>\n",
    "\t</ul>\n",
    "\t</li>\n",
    "\t<li>根据单词在句子中的索引，在单词最后添加与索引相同数量的字母<code>'a'</code>，索引从 <code>1</code> 开始。\n",
    "\t<ul>\n",
    "\t\t<li>例如，在第一个单词后添加 <code>\"a\"</code> ，在第二个单词后添加 <code>\"aa\"</code> ，以此类推。</li>\n",
    "\t</ul>\n",
    "\t</li>\n",
    "</ul>\n",
    "\n",
    "<p>返回将 <code>sentence</code> 转换为山羊拉丁文后的句子。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>sentence = \"I speak Goat Latin\"\n",
    "<strong>输出：</strong>\"Imaa peaksmaaa oatGmaaaa atinLmaaaaa\"\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>sentence = \"The quick brown fox jumped over the lazy dog\"\n",
    "<strong>输出：</strong>\"heTmaa uickqmaaa rownbmaaaa oxfmaaaaa umpedjmaaaaaa overmaaaaaaa hetmaaaaaaaa azylmaaaaaaaaa ogdmaaaaaaaaaa\"\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= sentence.length &lt;= 150</code></li>\n",
    "\t<li><code>sentence</code> 由英文字母和空格组成</li>\n",
    "\t<li><code>sentence</code> 不含前导或尾随空格</li>\n",
    "\t<li><code>sentence</code> 中的所有单词由单个空格分隔</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [goat-latin](https://leetcode.cn/problems/goat-latin/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [goat-latin](https://leetcode.cn/problems/goat-latin/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"I speak Goat Latin\"', '\"The quick brown fox jumped over the lazy dog\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        y = 'aeiou'\n",
    "        ori = sentence.split()\n",
    "        new = []\n",
    "        for i in range(len(ori)):\n",
    "            c = ori[i]\n",
    "            if c[0].lower() in y:\n",
    "                n = c\n",
    "\n",
    "            else:\n",
    "                n = c[1:] + c[0] \n",
    "            new.append(n + 'ma' + 'a' * (i + 1))\n",
    "        s = ' '.join(new)\n",
    "        \n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        d=['a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U']\n",
    "        sentence=sentence.split()\n",
    "        ans=\"\"\n",
    "        for i in range(len(sentence)):\n",
    "            if sentence[i][0] in d:\n",
    "                ans += sentence[i] + \"ma\" + \"a\"*(i+1)+\" \"\n",
    "            else:\n",
    "                ans +=(sentence[i]+sentence[i][0])[1:]+ \"ma\" + \"a\"*(i+1)+\" \"\n",
    "        # print(ans[:-1])\n",
    "        return ans[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "VOWELS = \"aeiouAEIOU\"\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        return \" \".join((s if s[0] in VOWELS else s[1:] + s[0]) + \"ma\" + \"a\" * i for i, s in enumerate(sentence.split(\" \"), 1))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words=sentence.split()\n",
    "        yyzm=set('aeiouAEIOU')\n",
    "        result=[]\n",
    "        for i, word in enumerate(words, 1):\n",
    "            if word[0] in yyzm:\n",
    "                new_word = word + 'ma'\n",
    "            else:\n",
    "                new_word = word[1:] + word[0] + 'ma'\n",
    "            new_word+='a'*i\n",
    "            result.append(new_word)\n",
    "        return ' '.join(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        res = []\n",
    "        words = sentence.split()\n",
    "        VOWEL_SET = set('aeiouAEIOU')\n",
    "        count = 2\n",
    "        for word in words:\n",
    "            if word[0] in VOWEL_SET:\n",
    "                res.append(word + 'm' + 'a' * count)\n",
    "            else:\n",
    "                res.append(word[1:] + word[0] + 'm' + 'a' * count)\n",
    "            count += 1\n",
    "        return \" \".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        a='aeiou'\n",
    "        b,c=[],'a'\n",
    "        for i in sentence.split(' '):\n",
    "            if i.lower()[0] in a:\n",
    "                b.append(i+'ma'+c)\n",
    "            else:\n",
    "                b.append(i[1:]+i[0]+'ma'+c)\n",
    "            c+='a'\n",
    "        return ' '.join(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        # result = \"\"\n",
    "        # split_result = sentence.split(\" \")\n",
    "\n",
    "        # list_ = [\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"]\n",
    "\n",
    "        # for i in range(len(split_result)):\n",
    "        #     temp = split_result[i]\n",
    "        #     if temp[0] in list_:\n",
    "        #         temp = temp + \"ma\"\n",
    "        #     else:\n",
    "        #         temp = temp[1:] + temp[0] + \"ma\"\n",
    "        #     temp = temp + \"a\" * (i + 1)\n",
    "\n",
    "        #     # if i == len(split_result) - 1:\n",
    "        #     #     result = result  + temp \n",
    "        #     # else:\n",
    "        #     result = result  + temp + \" \"\n",
    "\n",
    "        # return result[:-1]\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowel = ['a', 'e', 'i', 'o', 'u']\n",
    "        words = sentence.split(' ')\n",
    "        a = \"a\"\n",
    "        ans = []\n",
    "        for w in words:\n",
    "            t = w\n",
    "            if w[0].lower() in vowel:\n",
    "                pass\n",
    "            else:\n",
    "                t = '{}{}'.format(t[1:], t[0])\n",
    "            ans.append('{}ma{}'.format(t, a))\n",
    "            a = '{}a'.format(a)\n",
    "        return ' '.join(ans)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        yuanyin_list = [\"a\", \"e\",\"i\",\"o\",\"u\",\"A\", \"E\",\"I\",\"O\",\"U\"]\n",
    "        words_list = sentence.split(\" \")\n",
    "        res = \"\"\n",
    "        for i, word in enumerate(words_list):\n",
    "            if word[0] in yuanyin_list:\n",
    "                res += word + \"ma\" + \"a\" * (i+1) + \" \"\n",
    "            else:\n",
    "                res += word[1:]+word[0] + \"ma\" + \"a\" * (i+1) + \" \"\n",
    "        res = res[:-1]\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        ss = sentence.split(' ')\n",
    "        table = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        res = []\n",
    "        for i in range(len(ss)):\n",
    "            s = list(ss[i])\n",
    "            if s[0] in table:\n",
    "                s.append(\"ma\")\n",
    "                s.append(\"a\"*(i+1))\n",
    "                res.append(''.join(s))\n",
    "            else:\n",
    "                s.append(s[0])\n",
    "                del s[0]\n",
    "                s.append(\"ma\")\n",
    "                s.append(\"a\"*(i+1))\n",
    "                res.append(''.join(s))\n",
    "        return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentence = sentence.split(' ')\n",
    "        tone = {'a','e','i','o','u','A','E','I','O','U'}\n",
    "        result = []\n",
    "        for i, word in enumerate(sentence):\n",
    "            if word[0] in tone: word = word + 'ma'\n",
    "            else: word = word[1:] + word[0] + 'ma'\n",
    "            word = word + 'a'*(i+1)\n",
    "            result.append(word)\n",
    "        return ' '.join(result)                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        yuan = ['a', 'e', 'i', 'o', 'u']\n",
    "        s_list = sentence.split(' ')\n",
    "        res = ''\n",
    "        for index, word in enumerate(s_list):\n",
    "            if word[0].lower() in yuan:\n",
    "                word += 'ma'\n",
    "            else:\n",
    "                start = word[0]\n",
    "                if len(word) == 1:\n",
    "                    word = word + 'ma'\n",
    "                else:\n",
    "                    word = word[1:] + start + 'ma'\n",
    "            word += 'a'*(index + 1)\n",
    "            res += word\n",
    "            res += ' '\n",
    "        return res.rstrip()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words = sentence.split(\" \")\n",
    "        yy = ['a','e','i','o','u']\n",
    "        ans = []\n",
    "        for i,word in enumerate(words):\n",
    "            if word[0].lower() in yy:\n",
    "                word = word + \"ma\"\n",
    "            else:\n",
    "                word = word[1:] + word[0] + \"ma\"\n",
    "            word += (i+1)*'a'\n",
    "            ans.append(word)\n",
    "\n",
    "        return \" \".join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        d = ('a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U')\n",
    "        words = sentence.split()\n",
    "        for i, w in enumerate(words):\n",
    "            if w[0] in d:\n",
    "                words[i] = w + 'ma' + 'a' * (i + 1)\n",
    "            else:\n",
    "                words[i] = w[1:] + w[0] + 'ma' + 'a' * (i + 1)\n",
    "        #\n",
    "        return ' '.join(words)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words = sentence.split(' ')\n",
    "        vowel = 'aeiou'\n",
    "        ans = []  \n",
    "        for index, word in enumerate(words):\n",
    "            suffix = ''\n",
    "            if word[0].lower() in vowel:\n",
    "                suffix += 'ma'\n",
    "                w = word\n",
    "            else:\n",
    "                suffix += word[0] + 'ma'\n",
    "                w = word[1:]\n",
    "            suffix += 'a'*(index+1)\n",
    "            ans.append(w + suffix)\n",
    "        return ' '.join(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        res = sentence.split()\n",
    "        count = 2\n",
    "        for i in range(len(res)):\n",
    "            if res[i][0] not in 'aeiouAEIOU':\n",
    "                res[i] = res[i][1:] + res[i][0]\n",
    "            res[i] += 'm' + 'a' * count\n",
    "            count += 1\n",
    "        return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vocals=['a','e','i','o','u','A','E','I','O','U']\n",
    "        res=[]\n",
    "        temp=sentence.split(' ')\n",
    "        temp=[e.strip() for e in temp]\n",
    "        for i,e in enumerate(temp):\n",
    "            res.append( ( e+'ma' if e[0] in vocals else e[1:]+e[0]+'ma'    ) +'a'*(i+1)  )\n",
    "        return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sen_l = sentence.split(' ')\n",
    "        n = len(sen_l)\n",
    "        for i in range(n):\n",
    "            if sen_l[i].lower()[0] in ['a', 'e', 'i', 'o', 'u']:\n",
    "                sen_l[i] += 'ma'\n",
    "            else:\n",
    "                if len(sen_l[i]) == 1:\n",
    "                    sen_l[i] += 'ma'\n",
    "                else:\n",
    "                    sen_l[i] = sen_l[i][1:] + sen_l[i][0] + 'ma'\n",
    "            sen_l[i] += 'a'*(i+1)\n",
    "        return ' '.join(sen_l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words = sentence.split(\" \")\n",
    "        for i in range(len(words)) :\n",
    "            count_a = i + 1 \n",
    "            word = words[i]\n",
    "            if self.check(word[0]): \n",
    "                word += \"ma\"\n",
    "            else :\n",
    "                x = word[0]\n",
    "                word = word[1:]\n",
    "                word += x\n",
    "                word += \"ma\"\n",
    "            word += 'a' * count_a\n",
    "            words[i] = word\n",
    "        ans = \"\"\n",
    "        for word in words :\n",
    "            ans += word\n",
    "            ans += \" \"\n",
    "        \n",
    "        return ans[:-1]\n",
    "\n",
    "\n",
    "    def check(self ,x : str) -> bool :\n",
    "        return 2130466 >> (ord(x)&31) & 1 > 0 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        aeiou = 'aeiouAEIOU'\n",
    "        sentence = sentence.split(' ')\n",
    "        result = ''\n",
    "        for i in range(len(sentence)):\n",
    "            if( sentence[i][0] in aeiou ):\n",
    "                sentence[i] = sentence[i] + 'ma' + ('a'*(i+1))\n",
    "            else:\n",
    "                a = sentence[i][0]\n",
    "                sentence[i] = sentence[i][1:] + a + 'ma' + ('a'*(i+1))\n",
    "            result += sentence[i] + ' '\n",
    "        return result[:-1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def toGoatLatin(self, sentence: str) -> str:\r\n",
    "        vowles='aeiou'\r\n",
    "        ret=[]\r\n",
    "        start=0\r\n",
    "        def handle(word:str):\r\n",
    "            if word[0].lower() in vowles:\r\n",
    "                return word+'ma'+'a'*(len(ret)+1)\r\n",
    "            return word[1:]+word[0]+'ma'+'a'*(len(ret)+1)\r\n",
    "        for i,c in enumerate(sentence):\r\n",
    "            if c==' ':\r\n",
    "                ret.append(handle(sentence[start:i]))\r\n",
    "                start=i+1\r\n",
    "        ret.append(handle(sentence[start:]))\r\n",
    "        return ' '.join(ret)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "VOVEL = 'aeiouAEIOU'\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        ans = []\n",
    "        for i, w in enumerate(sentence.split(), 1):\n",
    "            if w[0] not in VOVEL:\n",
    "                w = w[1:] + w[0]\n",
    "            ans.append(w + 'ma' + 'a' * i)\n",
    "        return ' '.join(ans)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        s_list = sentence.split(\" \")\n",
    "        res = []\n",
    "        m = \"aeiouAEIOU\"\n",
    "        for k, i in enumerate(s_list):\n",
    "            if i[0] in m:\n",
    "                res.append(i+\"ma\"+(k+1)*\"a\")\n",
    "            else:\n",
    "                res.append(i[1:]+i[0]+\"ma\"+(k+1)*\"a\")\n",
    "        return \" \".join(res)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        return \"\".join([(s if s[0] in \"aeiouAEIUO\" else s[1:] + s[0]) + \"ma\" + \"a\" * (m+1) + \" \" for m,s in enumerate(sentence.split())])[:-1]\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "        s_list = sentence.split(' ')\n",
    "        for i, s in enumerate(s_list):\n",
    "            if s[0] in vowels:\n",
    "                s += \"ma\"\n",
    "            else:\n",
    "                s = s[1:] + s[0] +  \"ma\"\n",
    "            s += 'a' * (i + 1)\n",
    "            s_list[i] = s\n",
    "        return ' '.join(s_list)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        list1 = sentence.split()\n",
    "        a = ['a','A','e','E','i','I','o','O','u','U']\n",
    "        for i in range(len(list1)):\n",
    "            if list1[i][0] in a:\n",
    "                list1[i] = list1[i]+'ma'+(i+1)*'a'\n",
    "            else:\n",
    "                list1[i] = list1[i][1:]+list1[i][0]+'ma'+(i+1)*'a'\n",
    "            \n",
    "        return ' '.join(list1)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        l = sentence.split(' ')\n",
    "        res = []\n",
    "        for i in range(len(l)):\n",
    "            if l[i][0] in 'aeiouAEIOU':\n",
    "                x = l[i] + 'ma'\n",
    "            else:\n",
    "                x = l[i][1::]+l[i][0] + 'ma'\n",
    "            x = x + ('a'*(i+1))\n",
    "            res.append(x)\n",
    "        return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words=sentence.split()\n",
    "        yyzm=set('aeiouAEIOU')\n",
    "        result=[]\n",
    "        for i, word in enumerate(words, 1):\n",
    "            if word[0] in yyzm:\n",
    "                new_word = word + 'ma'\n",
    "            else:\n",
    "                new_word = word[1:] + word[0] + 'ma'\n",
    "            new_word+='a'*i\n",
    "            result.append(new_word)\n",
    "        return ' '.join(result)\n",
    "        sentence = \"I speak Goat Latin\"\n",
    "        result = toGoatLatin(sentence)\n",
    "        print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        result = []\n",
    "        words = sentence.split()\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                word += 'ma'\n",
    "            else :\n",
    "                word = word[1:] + word[:1] + 'ma'\n",
    "            word += 'a' * (i + 1)\n",
    "            result.append(word)\n",
    "        return ' '.join(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        li=sentence.split()\n",
    "        yuan=[\"a\",\"e\",\"i\",\"o\",\"u\",\"A\",\"E\",\"I\",\"O\",\"U\"]\n",
    "        sen=\"\"\n",
    "        i=1\n",
    "        for word in li :\n",
    "            ch=word;\n",
    "            if word[0] in yuan:\n",
    "                ch+=\"ma\"\n",
    "            else:\n",
    "                ch=ch[1:]+ch[0]\n",
    "                ch+=\"ma\"\n",
    "            ch+=\"a\"*i\n",
    "            i+=1\n",
    "            sen+=ch+\" \"\n",
    "        return sen[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "      s = {'a','A', 'e','E', 'i','I', 'o','O', 'u','U'}\n",
    "      res = ''\n",
    "      for i,w in enumerate(sentence.split()):\n",
    "        t = ''\n",
    "        if w[0] in s:\n",
    "          t = w+'ma'+(i+1)*'a'\n",
    "        else:\n",
    "          t = w[1:]+w[0]+'ma'+(i+1)*'a'\n",
    "        res += t + ' '\n",
    "      res = res.rstrip()\n",
    "      return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        array = sentence.split(\" \")\n",
    "        for key in range(len(array)):\n",
    "            if array[key][0] in list('aeiouAEIOU'):\n",
    "                array[key] = f\"{array[key]}ma\"\n",
    "            else:\n",
    "                array[key] = f\"{array[key][1:]}{array[key][0]}ma\"\n",
    "            array[key] = f\"{array[key]}{(key+1) * 'a'}\"\n",
    "        return \" \".join(array)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        res = \"\"\n",
    "        _ = \"AEIOUaeiou\"\n",
    "        str_split = sentence.split(\" \")\n",
    "        count = 1\n",
    "        for word in str_split:\n",
    "            if word[0] in _ or len(word) == 1:\n",
    "                res += word\n",
    "            else:\n",
    "                res += word[1:]\n",
    "                res += word[0]\n",
    "            res += \"ma\"\n",
    "            res += \"a\" * count\n",
    "            count += 1\n",
    "            res += \" \"\n",
    "        return res[0:len(res) - 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\tdef toGoatLatin(self, s):\n",
    "\t\ta = s.split(' ')\n",
    "\t\tfor i, w in enumerate(a):\n",
    "\t\t\tif w[0] in 'aeiouAEIOU':\n",
    "\t\t\t\tw += 'ma'\n",
    "\t\t\telse:\n",
    "\t\t\t\tw = w[1:] + w[0] + 'ma'\n",
    "\t\t\ta[i] = w + 'a' * (i + 1)\n",
    "\t\treturn ' '.join(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "VOWELS = \"aeiouAEIOU\"\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        return \" \".join((s if s[0] in VOWELS else s[1:] + s[0]) + \"ma\" + \"a\" * i for i, s in enumerate(sentence.split(\" \"), 1))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentencelst = sentence.split(\" \")\n",
    "        for i in range(len(sentencelst)):\n",
    "            if sentencelst[i][0] in \"aeiouAEIOU\":\n",
    "                sentencelst[i] = sentencelst[i] + \"ma\" + (i+1)*\"a\"\n",
    "            else:\n",
    "                sentencelst[i] = sentencelst[i][1:] + sentencelst[i][0] + \"ma\" + (i+1)*\"a\"\n",
    "        return \" \".join(sentencelst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        result = \"\"\n",
    "        split_result = sentence.split(\" \")\n",
    "\n",
    "        list_ = [\"a\", \"e\", \"i\", \"o\", \"u\"]\n",
    "\n",
    "        for i in range(len(split_result)):\n",
    "            temp = split_result[i]\n",
    "            if temp[0].lower() in list_:\n",
    "                temp = temp + \"ma\"\n",
    "            else:\n",
    "                temp = temp[1:] + temp[0] + \"ma\"\n",
    "            temp = temp + \"a\" * (i + 1)\n",
    "\n",
    "            if i == len(split_result) - 1:\n",
    "                result = result  + temp \n",
    "            else:\n",
    "                result = result  + temp + \" \"\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        s=sentence.split(' ')\n",
    "        vowels={'a','e','i','o','u','A','E','I','O','U'}\n",
    "        n=len(s)\n",
    "        res=[]\n",
    "        for i in range(n):\n",
    "            if s[i][0] in vowels:\n",
    "                res+=[s[i]+'ma'+(i+1)*'a']\n",
    "            else:\n",
    "                res+=[s[i][1:]+s[i][0]+'ma'+(i+1)*'a']\n",
    "        ans=''\n",
    "        for i in range(n-1):\n",
    "            ans+=res[i]+' '\n",
    "        ans+=res[n-1]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        a = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}\n",
    "\n",
    "        i = 0\n",
    "        n = 1\n",
    "        res = []\n",
    "\n",
    "        while i<len(sentence):\n",
    "            j = i \n",
    "            while j < len(sentence) and sentence[j]!=\" \":\n",
    "                j+=1\n",
    "            n+=1\n",
    "            if sentence[i] in a:\n",
    "                res.append(sentence[i:j]+'m'+'a'*n)\n",
    "            else:\n",
    "                res.append(sentence[i+1:j]+sentence[i]+'m'+'a'*n)\n",
    "\n",
    "            i = j+1\n",
    "        return \" \".join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        word_set=set('aeiouAEIOU')\n",
    "        result=list()\n",
    "\n",
    "        for index,word in enumerate(sentence.split(' ')):\n",
    "            if word[0] in word_set:\n",
    "                result.append(word+'ma'+'a'*(index+1))\n",
    "            else:\n",
    "                result.append(word[1:]+word[0]+'ma'+'a'*(index+1))\n",
    "        return ' '.join(result)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        result = \"\"\n",
    "        split_result = sentence.split(\" \")\n",
    "\n",
    "        list_ = [\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"]\n",
    "\n",
    "        for i in range(len(split_result)):\n",
    "            temp = split_result[i]\n",
    "            if temp[0] in list_:\n",
    "                temp = temp + \"ma\"\n",
    "            else:\n",
    "                temp = temp[1:] + temp[0] + \"ma\"\n",
    "            temp = temp + \"a\" * (i + 1)\n",
    "\n",
    "            # if i == len(split_result) - 1:\n",
    "            #     result = result  + temp \n",
    "            # else:\n",
    "            result = result  + temp + \" \"\n",
    "\n",
    "        return result[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        return ' '.join((s[1:]+s[0], s)[s[0] in 'aeiouAEIOU']+'m'+'a'*cnt for cnt, s in enumerate(sentence.split(), 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)    \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentence=sentence.split(\" \")\n",
    "        a=['a','e','i','o','u','A','E','I','O','U']\n",
    "        b=[]\n",
    "        for i in range(len(sentence)):\n",
    "            if sentence[i][0] in a :\n",
    "                b.append(sentence[i]+'ma'+(i+1)*'a')\n",
    "            else:\n",
    "                b.append(sentence[i][1:]+sentence[i][0]+'ma'+(i+1)*'a')\n",
    "        return \" \".join(b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words = sentence.split(' ')\n",
    "        n = len(words)\n",
    "        aeiou = ['a','e','i','o','u']\n",
    "        r = ''\n",
    "        for i in range(n):\n",
    "            r += 'a'\n",
    "            if words[i].lower()[0] in aeiou:\n",
    "                words[i] = str(words[i]) + 'ma' + r + ' '\n",
    "                print(r)\n",
    "            else:\n",
    "                words[i] = str(words[i][1:]) + str(words[i][0]) + 'ma' + r + ' '\n",
    "        print(words)\n",
    "        return ''.join(words)[:-1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        words, p = sentence.split(), \"aeiouAEIOU\"\n",
    "        for i, word in enumerate(words):\n",
    "            if word[0] in p:\n",
    "                words[i] += \"maa\" + 'a' * i\n",
    "            else:\n",
    "                words[i] = word[1:] + word[0] + \"maa\" + 'a' * i\n",
    "        return ' '.join(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = set(\"aeiouAEIOU\")\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = []\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        result = \"\"\n",
    "        split_result = sentence.split(\" \")\n",
    "\n",
    "        list_ = [\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"]\n",
    "\n",
    "        for i in range(len(split_result)):\n",
    "            temp = split_result[i]\n",
    "            if temp[0] in list_:\n",
    "                temp = temp + \"ma\"\n",
    "            else:\n",
    "                temp = temp[1:] + temp[0] + \"ma\"\n",
    "            temp = temp + \"a\" * (i + 1)\n",
    "\n",
    "            # if i == len(split_result) - 1:\n",
    "            #     result = result  + temp \n",
    "            # else:\n",
    "            result = result  + temp + \" \"\n",
    "\n",
    "        return result[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        tmp=sentence.split(' ')\n",
    "        dl=['a','e','i','o','u','A','E','I','O','U']\n",
    "\n",
    "        for i in range(len(tmp)):\n",
    "            if tmp[i][0] in dl:\n",
    "                tmp[i]=tmp[i]+'ma'\n",
    "            else:\n",
    "                tmp[i]=tmp[i][1:]+tmp[i][0]+'ma'\n",
    "        \n",
    "        for i in range(len(tmp)):\n",
    "            tmp[i]=tmp[i]+(i+1)*'a'\n",
    "        \n",
    "        return ' '.join(tmp)\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        res = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        ans = []\n",
    "        n = len(sentence)\n",
    "        temp = \"\"\n",
    "        for i in range(n):\n",
    "            if i == n-1:\n",
    "                temp += sentence[i]\n",
    "                ans.append(temp)\n",
    "            elif sentence[i] != ' ' and sentence[i+1] == ' ':\n",
    "                temp += sentence[i]\n",
    "                ans.append(temp)\n",
    "                temp = \"\"\n",
    "            elif sentence[i] != ' ':\n",
    "                temp += sentence[i]\n",
    "        for i in range(len(ans)):\n",
    "            if ans[i][0] not in res:\n",
    "                temp = ans[i][0]\n",
    "                ans[i] = ans[i][1:]\n",
    "                ans[i] += temp\n",
    "            ans[i] += \"ma\"\n",
    "            ans[i] += \"a\" * (i+1)\n",
    "        res = \"\"\n",
    "        for i in ans:\n",
    "            res += i\n",
    "            res += ' '\n",
    "        return res[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        ans = []\n",
    "        s_l = sentence.split()\n",
    "        pattern = r\"^[^aeiou]\"\n",
    "        for i in range(len(s_l)):\n",
    "            matche = re.search(pattern, s_l[i], re.I)\n",
    "            if matche:\n",
    "                s_l[i] = s_l[i][1:] + s_l[i][0]\n",
    "            \n",
    "            s_l[i] = s_l[i] + \"ma\" + 'a'*(i+1)\n",
    "            ans.append(s_l[i])\n",
    "        \n",
    "        return \" \".join(ans)\n",
    "        \n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        ls=sentence.split()\n",
    "        for i,s in enumerate(ls):\n",
    "            if s[0] in ['a', 'e', 'i', 'o', 'u',\"A\",\"E\",\"I\",\"O\",\"U\"]:\n",
    "                ls[i]=ls[i]+\"ma\"\n",
    "            else:\n",
    "                ls[i]=ls[i][1:]+ls[i][0]+\"ma\"\n",
    "            ls[i]=ls[i]+\"a\"*(i+1)\n",
    "        return \" \".join(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# Python3\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sarr = sentence.split(' ')\n",
    "        alist = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        for i in range(len(sarr)):\n",
    "            if sarr[i][0] in alist:\n",
    "                sarr[i] += 'ma' + (i+1)*'a'\n",
    "            else:\n",
    "                sarr[i] = sarr[i][1:] + sarr[i][0] + 'ma' + (i+1)*'a'\n",
    "        return ' '.join(sarr)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        open = ['a','e','i','o','u']\n",
    "        last = 'maa'\n",
    "        list = sentence.split(' ')\n",
    "        result = []\n",
    "        for i in list:\n",
    "            if i[0].lower() in open:\n",
    "                result.append(i+last)\n",
    "            else:\n",
    "                result.append(i[1:]+i[0]+last)\n",
    "            last += 'a'\n",
    "        return ' '.join(result)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "      s = {'a','A', 'e','E', 'i','I', 'o','O', 'u','U'}\n",
    "      l = sentence.split()\n",
    "      res = []\n",
    "      for i,w in enumerate(l):\n",
    "        t = ''\n",
    "        if w[0] in s:\n",
    "          t = w+'ma'+(i+1)*'a'\n",
    "        else:\n",
    "          t = w[1:]+w[0]+'ma'+(i+1)*'a'\n",
    "        res.append(t)\n",
    "      return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "        ls = sentence.split()\n",
    "        n = len(ls)\n",
    "        for i in range(n):\n",
    "            if ls[i][0] in vowels:\n",
    "                ls[i] = ls[i] + \"ma\" + (i+1)*\"a\"\n",
    "            else:\n",
    "                ls[i] = ls[i][1:] + ls[i][0] + \"ma\" + (i+1) *\"a\"\n",
    "        return ' '.join(ls)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowels = {\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"}\n",
    "\n",
    "        n = len(sentence)\n",
    "        i, cnt = 0, 1\n",
    "        words = list()\n",
    "\n",
    "        while i < n:\n",
    "            j = i\n",
    "            while j < n and sentence[j] != \" \":\n",
    "                j += 1\n",
    "            \n",
    "            cnt += 1\n",
    "            if sentence[i] in vowels:\n",
    "                words.append(sentence[i:j] + \"m\" + \"a\" * cnt)\n",
    "            else:\n",
    "                words.append(sentence[i+1:j] + sentence[i] + \"m\" + \"a\" * cnt)\n",
    "            \n",
    "            i = j + 1\n",
    "        \n",
    "        return \" \".join(words)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        rev_sentence = sentence.split()\n",
    "        for i in range(len(rev_sentence)):\n",
    "            if rev_sentence[i][0] in 'aeiouAEIOU':\n",
    "                rev_sentence[i] += 'ma'\n",
    "            else:\n",
    "                rev_sentence[i] = rev_sentence[i][1:] + rev_sentence[i][0] + 'ma'\n",
    "            rev_sentence[i] += 'a'*(i+1)\n",
    "        return ' '.join(rev_sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        lst=sentence.split(\" \")\n",
    "        string=\"ma\"\n",
    "        for i in range(len(lst)):\n",
    "            string+=\"a\"\n",
    "            if lst[i][0].lower()!=\"a\" and lst[i][0].lower()!=\"e\" and lst[i][0].lower()!=\"i\" and lst[i][0].lower()!=\"o\" and lst[i][0].lower()!=\"u\":\n",
    "                lst[i]=lst[i][1:]+lst[i][:1]+string\n",
    "            else:\n",
    "                lst[i]+=string\n",
    "        return \" \".join(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        # return ' '.join(i+'ma'+'a'*(i+1) if i[0]in 'aeiou' else i[1:]+i[0]+'ma'+'a'*(i+1) for i in sentence.split())\n",
    "        sentence=sentence.split()\n",
    "        for i in range(len(sentence)):\n",
    "            if sentence[i][0]in 'aeiouAEIOU':\n",
    "                sentence[i]=sentence[i]+'ma'\n",
    "                for j in range(i+1):\n",
    "                    sentence[i]+='a'\n",
    "            else:\n",
    "                sentence[i]=sentence[i][1:]+sentence[i][0]+'ma'\n",
    "                for j in range(i+1):\n",
    "                    sentence[i]+='a'\n",
    "        return ' '.join(sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        vowel = ['a','e','i','o','u','A','E','I','O','U']\n",
    "        sentence_new = ''\n",
    "        sentence = sentence.split(' ')\n",
    "        for i,word in enumerate(sentence):\n",
    "            if word[0] in vowel:\n",
    "                word +='ma'\n",
    "            if word[0] not in vowel:\n",
    "                word  = word[1::] + word[0]+'ma'\n",
    "            for j in range(i+1):\n",
    "                word += 'a'\n",
    "            sentence_new = sentence_new + ' '+ word\n",
    "        return sentence_new.lstrip(' ')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        jh = set(\"aeiouAEIOU\")\n",
    "        x = 0\n",
    "        w = \"\"\n",
    "        fh = []\n",
    "        for i, j in enumerate(sentence):\n",
    "            if j == \" \":\n",
    "                if sentence[x] in jh:\n",
    "                    fh.append(sentence[x:i]+\"ma\"+\"a\"*(len(fh)+1))\n",
    "                else:\n",
    "                    fh.append(sentence[x+1:i]+sentence[x]+\"ma\"+\"a\"*(len(fh)+1))\n",
    "                x = i+1\n",
    "        if sentence[x] in jh:\n",
    "            fh.append(sentence[x:i+1]+\"ma\"+\"a\"*(len(fh)+1))\n",
    "        else:\n",
    "            fh.append(sentence[x+1:i+1]+sentence[x]+\"ma\"+\"a\"*(len(fh)+1))\n",
    "        return \" \".join(fh)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentence=sentence.split(' ')\n",
    "        for i in range(len(sentence)):\n",
    "            w=sentence[i]\n",
    "            if w[0].lower() in 'aeiou':\n",
    "                sentence[i]=w+'ma'+(i+1)*'a'\n",
    "            else:\n",
    "                sentence[i]=w[1:]+w[0]+'ma'+(i+1)*'a'\n",
    "        return ' '.join(sentence)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentence = sentence.split()\n",
    "        for i in range(len(sentence)):\n",
    "            if sentence[i][0] in 'AEIOUaeiou':\n",
    "                sentence[i] += 'm' + 'a' * (i+2)\n",
    "            else:\n",
    "                sentence[i] += sentence[i][0] + 'm' + 'a' * (i+2)\n",
    "                sentence[i] = sentence[i][1:]\n",
    "        def x(a,b):\n",
    "            return a+' '+b\n",
    "        return reduce(x, sentence)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def toGoatLatin(self, sentence: str) -> str:\r\n",
    "        words = sentence.split()\r\n",
    "        for i in range(len(words)):\r\n",
    "            word = words[i]\r\n",
    "            if word.startswith((\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\")):\r\n",
    "                words[i] = word\r\n",
    "            else:\r\n",
    "                words[i] = word[1:] + word[0]\r\n",
    "            words[i] += (\"ma\" + \"a\" * (i+1))\r\n",
    "        return \" \".join(words)\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        sentence = sentence.split(' ')\n",
    "        for i in range(len(sentence)):\n",
    "            if sentence[i][0] in ('a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U'):\n",
    "                sentence[i] = sentence[i] + 'ma' + (i+1)*'a'\n",
    "            else:\n",
    "                sentence[i] = sentence[i][1:] + sentence[i][0] + 'ma' + (i+1)*'a'\n",
    "        return ' '.join(sentence)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def toGoatLatin(self, sentence: str) -> str:\r\n",
    "        words = sentence.split()\r\n",
    "        res = []\r\n",
    "        vowel = set(['a', 'e', 'i', 'o', 'u'])\r\n",
    "        for i, word in enumerate(words):\r\n",
    "            if word[0].lower() not in vowel:\r\n",
    "                word = word[1:] + word[0]\r\n",
    "            word += 'ma' + 'a' * (i+1)\r\n",
    "            res.append(word)\r\n",
    "        return ' '.join(res)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        Word = sentence.split()\n",
    "        count = 2\n",
    "        NewSentencce = ''\n",
    "        for i in Word:\n",
    "            if i[0] in ['a','e','i','o','u','A','E','I','O','U']:\n",
    "                i += 'm'\n",
    "                i += 'a'*count\n",
    "                NewSentencce+=i+' '\n",
    "            else:\n",
    "                i = i[1:]+i[0]\n",
    "                i += 'm'\n",
    "                i += 'a'*count\n",
    "                NewSentencce+=i+' '\n",
    "            count+=1\n",
    "        \n",
    "        NewSentencce=NewSentencce[:-1]\n",
    "        return NewSentencce\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        a=sentence.split()\n",
    "        x={'a', 'e', 'i', 'o', 'u','A','E','I','O','U'}\n",
    "        t=[]\n",
    "        for i,j in enumerate(a):\n",
    "            if j[0] in x:\n",
    "                t.append(j+'ma'+'a'*(i+1))\n",
    "            else:\n",
    "                t.append(j[1:]+j[0]+'ma'+'a'*(i+1))\n",
    "        return ' '.join(t)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        result = \"\"\n",
    "        split_result = sentence.split(\" \")\n",
    "\n",
    "        list_ = [\"a\", \"e\", \"i\", \"o\", \"u\", \"A\", \"E\", \"I\", \"O\", \"U\"]\n",
    "\n",
    "        for i in range(len(split_result)):\n",
    "            temp = split_result[i]\n",
    "            if temp[0] in list_:\n",
    "                temp = temp + \"ma\"\n",
    "            else:\n",
    "                temp = temp[1:] + temp[0] + \"ma\"\n",
    "            temp = temp + \"a\" * (i + 1)\n",
    "\n",
    "            # if i == len(split_result) - 1:\n",
    "            #     result = result  + temp \n",
    "            # else:\n",
    "            result = result  + temp + \" \"\n",
    "\n",
    "        return result[:-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        l1=['a','e','i','o','u']\n",
    "        l2=['b','c','d','f','g','h','j','k','l','m','n','p','q','r','s','t','v','w','x','y','z']\n",
    "        a=sentence.split()\n",
    "        for i in range(len(a)):\n",
    "            if a[i][0].lower() in l1:\n",
    "                a[i]=a[i]+'ma'\n",
    "            elif a[i][0].lower() in l2:\n",
    "                a[i]=str(a[i][1::])+a[i][0]+'ma'\n",
    "            a[i]+=(i+1)*'a'\n",
    "        return ' '.join(a)\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        lst=sentence.split()\n",
    "        for i in range(len(lst)):\n",
    "            if lst[i][0].upper() in 'AEIOU':\n",
    "                lst[i]=lst[i]+\"ma\"+\"a\"*(i+1)\n",
    "            else:\n",
    "                lst[i]=lst[i][1:]+lst[i][0]+\"ma\"+\"a\"*(i+1)\n",
    "\n",
    "        return \" \".join(lst)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def toGoatLatin(self, sentence: str) -> str:\n",
    "        list_yuan=['a', 'e', 'i', 'o', 'u','A', 'E', 'I', 'O', 'U']\n",
    "        list_=[s for s in sentence.split(' ')]\n",
    "        a=0\n",
    "        for i in list_:\n",
    "            if i[0] in list_yuan:\n",
    "                list_[a]+='ma'+'a'*(a+1)\n",
    "            else:\n",
    "                list_[a]=i[1:]+i[0]+'ma'+'a'*(a+1)\n",
    "            a+=1\n",
    "        return ' '.join(list_)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
